package com.mike.controller;

import com.mike.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Date 2021/11/29 16:52
 * @Created by mike
 */
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    /**
     * ⽣成验证码并发送到对应邮箱，成功true，失败false
     */
    @GetMapping("/create/{email}")
    public Boolean createCode(@PathVariable String email){
        return codeService.createCode(email);
    }

    /**
     * 校验验证码是否正确，0正确1错误2超时
     */
    @GetMapping("/validate/{email}/{code}")
    public Integer validateCode(@PathVariable String email,@PathVariable String code){
        return codeService.validateCode(email,code);
    }

}
